﻿function WebNoteEditor()
{
	var i,src;
	this.menubar=0;
	this.cssfiles="";
	this.id="editor";
	//默认ID
	this.toolbar="toolbar.xml";
	this.width="100%";
	this.height="500px";
	this.fullhtmlmode=0;
	this.mode="";
	this.canpagesplit="";
	this.skin="";
	
	this.language="";
	this.bindsubmitevent=1;

	var elem=document.getElementsByTagName("script");
	
	for (i=0;i<elem.length;i++)
	{
	
		src=elem[i].getAttribute("src");
		if (src)
		{
			if (src.toLowerCase().indexOf("webnoteeditor.js")>0)
			{
				this.basePath=src.toLowerCase().replace("/webnoteeditor.js","");
				break;
			}
		}
	}
	//编辑器使用的用户语言(默认使用浏览器的语言)
	this.xhtmlsupported="";

}

WebNoteEditor.prototype.show=function()
{
	if (this.language=="")
	{
		this.language=navigator.language?navigator.language.toLowerCase():window.clientInformation.browserLanguage;
	}

	if (this.fullhtmlmode=="")
		{this.fullhtmlmode=0;}
	if (this.mode="")
		{this.mode="Add";}
	else
		{this.mode="Update";}
		
	var pathName = location.pathname;
	
	//var tempStr=pathName.split(".");
	//var ServerISAPI=tempStr[tempStr.length-1];
	//if (ServerISAPI=="jsp" || ServerISAPI=="php")
		ServerISAPI="htm";

	document.write("<iframe id=\""+this.id+"\" src=\""+this.basePath+"/editor."+ServerISAPI+"?menubar="+this.menubar+"&id="+this.id+"&toolbar="+this.toolbar+"&fullhtmlmode="+this.fullhtmlmode+"&language="+this.language+"\&mode="+this.mode+"\&skin="+this.skin+"&xhtmlsupported="+this.xhtmlsupported+"&canpagesplit="+this.canpagesplit+"&cssfiles="+this.cssfiles+"&bindsubmitevent="+this.bindsubmitevent+"\" style=\"width:"+this.width+";height:"+this.height+"\" frameborder=\"0\" scrolling=\"no\"></iframe>");
}

WebNoteEditor.prototype.showAsInput=function()
{
	if (this.language=="")
	{
		this.language=navigator.language?navigator.language.toLowerCase():window.clientInformation.browserLanguage;
	}

	if (this.fullhtmlmode=="")
		{this.fullhtmlmode=0;}
	if (this.mode="")
		{this.mode="Add";}
	else
		{this.mode="Update";}
		
	var pathName = location.pathname;
	
	var tempStr=pathName.split(".");
	var ServerISAPI=tempStr[tempStr.length-1];
	if (ServerISAPI=="jsp" || ServerISAPI=="php")
		ServerISAPI="htm";
	this.bindsubmitevent=0;
	document.write("<input type=\"text\" id=\""+this.id+"_Text\" name=\""+this.id+"_Text\" style=\"px\">");
	document.write("<span id=\""+this.id+"_btn\" readonly  onclick=\"javascrit:displayEditor('"+this.id+"');\" style=\"background-image:url('"+this.basePath+"/images/editmode.gif');background-repeat:no-repeat;background-position:center center;background-color: #B5BED6;width:20px;height:20px;border: 1px solid #3D68B2;cursor:pointer\"></span>");
	
	document.write("<iframe id=\""+this.id+"\" style=\"display:none\" src2=\""+this.basePath+"/editor."+ServerISAPI+"?menubar="+this.menubar+"&id="+this.id+"&toolbar="+this.toolbar+"&fullhtmlmode="+this.fullhtmlmode+"&language="+this.language+"\&mode="+this.mode+"\&skin="+this.skin+"&xhtmlsupported="+this.xhtmlsupported+"&canpagesplit="+this.canpagesplit+"&cssfiles="+this.cssfiles+"&bindsubmitevent="+this.bindsubmitevent+"\" style=\"width:"+this.width+";height:"+this.height+"\" frameborder=\"0\" scrolling=\"no\"></iframe>");
}

var $timer;

function displayEditor(sID)
{
    if (document.getElementById(sID).style.display=="none")
    {
        document.getElementById(sID).style.display="";
        if (document.getElementById(sID).getAttribute("src2"))
        {
            document.getElementById(sID).contentWindow.location=document.getElementById(sID).getAttribute("src2");
            $timer=window.setInterval("__setHTML('"+sID+"')",1000);
        }
        document.getElementById(sID).removeAttribute("src2")
    }
    else
    {
        document.getElementById(sID).style.display="none";
    }
}

function __setHTML(sID)
{
    if (document.getElementById(sID).contentWindow.XEditor)
    {
        document.getElementById(sID).contentWindow.setHTML(document.getElementById(sID+"_Text").value,true);
        window.clearInterval($timer);
    }
}